import threading
import time

loop = 1000000
number = 0
lock=threading.Lock()

def add(count):
    global number
    lock.acquire()
    for i in range(count):
        number += 1
    lock.release()

def sub(count):
    global number
    lock.acquire()
    for i in range(count):
        number -= 1
    lock.release()

if __name__ == '__main__':
    start=time.time()
    t1 = threading.Thread(target=add, args=(loop,))
    t2 = threading.Thread(target=sub, args=(loop,))
    t1.start()
    t2.start()
    t1.join()
    t2.join()
    end=time.time()
    print('耗时:',end-start)
    print(number)
